﻿using System;

namespace Syngine
{
	/// <summary>
	/// Contains information about the current games state.
	/// </summary>
	public static class GameState
	{
		/// <summary>
		/// Occurs when [paused].
		/// </summary>
		public static event Action Paused;

		/// <summary>
		/// Occurs when [unpaused].
		/// </summary>
		public static event Action Resumed;

		/// <summary>
		/// Occurs when [pause changed].
		/// </summary>
		public static event Action<bool> PauseChanged;

		/// <summary>
		/// Gets a value indicating whether the game is paused.
		/// </summary>
		/// <value>
		///   <c>true</c> if the game is paused; otherwise, <c>false</c>.
		/// </value>
		public static bool IsPaused { get; private set; }

		private static void OnPaused()
		{
			var handler = Paused;

			if (handler != null)
			{
				handler();
			}
		}

		private static void OnResumed()
		{
			var handler = Resumed;

			if (handler != null)
			{
				handler();
			}
		}

		private static void OnPauseChanged(bool paused)
		{
			var handler = PauseChanged;

			if (handler != null)
			{
				handler(paused);
			}
		}

		/// <summary>
		/// Pauses this instance.
		/// </summary>
		public static void Pause()
		{
			IsPaused = true;
			OnPaused();
			OnPauseChanged(true);
		}

		/// <summary>
		/// Resumes this instance.
		/// </summary>
		public static void Resume()
		{
			IsPaused = false;
			OnResumed();
			OnPauseChanged(false);
		}
	}
}